<template>
  <div v-if="props.readonly && props.readonly==1">{{format}}</div>
  <el-select collapse-tags collapse-tags-tooltip :max-collapse-tags="1" :multiple="props.multiple==1" v-model="value" placeholder="请选择课程" :disabled="props.disabled" filterable clearable v-else>
    <el-option v-for="(item,index) in options" :key="index" :label="item.name" :value="item[value_format]" />
  </el-select>
</template>

<script setup lang="ts">
const { proxy } = getCurrentInstance();
let props = defineProps([
  "modelValue",
  "val",
  "readonly",
  "disabled",
  "multiple",
]);
const emit = defineEmits(["update:modelValue", "fatherMethods"]);
import useCounterStore from "@/store/counter";
const counter = useCounterStore();

let options = ref([]);

let format = computed(() => {
  if (!options.value.length) return;
  let index = proxy.$utils.findIndexByField(
    options.value,
    value_format.value,
    props.modelValue
  );
  return index > -1 ? options.value[index].name : "";
});

const value = computed({
  get() {
    return props.modelValue;
  },
  set(value) {
    emit("update:modelValue", value);
    emit("fatherMethods");
  },
});

let value_format = computed(() => {
  return props.val ? props.val : "_id";
});

onMounted(() => {
  getInfo();
});

async function getInfo() {
  if (counter.ycAdminParams.course && counter.ycAdminParams.course.length > 0) {
    options.value = counter.ycAdminParams.course;
  }
  options.value = await proxy.$apis.course({
    type: "query",
    data: { allData: true },
  });
  counter.setYcParams("course", options.value);
}
</script>



<style lang="scss" scoped>
.container {
}
</style>



